<?php

namespace App\Http\Controllers\Web\Shop;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Web\BaseController;
use App\Repository\Repositories\Interfaces\CompanyRepository;
use App\Repository\Repositories\Interfaces\ShopRepository;
use Illuminate\Http\Request;

/**
 * 退单管理控制器
 *
 * @package App\Http\Controllers\Seller
 */
class CompanyController extends BaseController
{
    /**
     * @var CompanyController
     */
    protected $company;

    public function __construct(CompanyRepository $company)
    {
        $this->company = $company;
    }

    public function show($id)
    {

        $company = $this->company->with(['companyMaterial','shop'])->find($id);

        if(!empty($company['data']['company_material']['business_trade'])){
            $business_trade=json_decode($company['data']['company_material']['business_trade'], true);
            $company['data']['company_material']['business_trade']=implode("、",$business_trade);
        }

        if(!empty($company['data']['company_material']['business_product'])) {
            $business_trade = json_decode($company['data']['company_material']['business_product'], true);
            $company['data']['company_material']['business_product'] = implode("、", $business_trade);
        }
        if(!empty($company['data']['company_material']['sales_region'])) {

            $business_trade = json_decode($company['data']['company_material']['sales_region'], true);
            $company['data']['company_material']['sales_region'] = implode("、", $business_trade);
        }
        if(!empty($company['data']['company_material']['customer_groups'])) {

            $business_trade = json_decode($company['data']['company_material']['customer_groups'], true);
            $company['data']['company_material']['customer_groups'] = implode("、", $business_trade);
        }


        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $company['data']);
    }

    public function company_show($id){
        $company = $this->company->with(['companyMaterial'=>function($sql){
            $sql->select('company_id','contact_mobile','contact_tel');
        }])->find($id);
        return $this->success(ErrorConst::SUCCESS_CODE_MSG, $company['data']);

    }

}
